N = 6040; M = 3952; K = 35;

load movielens/train;
load movielens/test;

fU = cell(1,N); 
fV = cell(1,M); 
fT = cell(1,K);

fprintf('building tensor indices ...\n');

for ii = 1:N
    idx = find(train(:,2)==ii);
    fU{ii}.jj = train(idx,3);
    fU{ii}.kk = train(idx,1);
    fU{ii}.vals = double(train(idx,4));
end

for jj = 1:M
    idx = find(train(:,3)==jj);
    fV{jj}.ii = train(idx,2);
    fV{jj}.kk = train(idx,1);
    fV{jj}.vals = double(train(idx,4));
end

for kk = 1:K
    idx = find(train(:,1)==kk);
    fT{kk}.ii = train(idx,2);
    fT{kk}.jj = train(idx,3);
    fT{kk}.vals = double(train(idx,4));
end